from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMainWindow
from PyQt5.QtGui import QPainter, QPixmap
import sys
from PyQt5.QtGui import QIcon

class MyWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("背景图片示例")
        self.setFixedSize(1600, 960)  # 固定窗口大小
        # 创建按钮
        self.button = QPushButton("", self)
        self.button.setGeometry(200, 150, 100, 100)  # 按钮大小
        self.button.setIcon(QIcon("../resources/logo.ico"))  # 按钮图标
        self.button.setIconSize(self.button.size())  # 图标填充按钮
        self.button.setStyleSheet("border: none; background: transparent;")  # 去掉边框
        self.button.clicked.connect(self.on_click)

    def on_click(self):
        print("按钮被点击了！")

    def paintEvent(self, event):
        painter = QPainter(self)
        pixmap = QPixmap("../resources/bg/background.png")
        painter.drawPixmap(self.rect(), pixmap)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MyWindow()
    window.show()
    sys.exit(app.exec_())